package cn.broadmax.boot.modules.aj.bean;

import cn.broadmax.boot.modules.aj.entity.JzManage;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mysql.cj.util.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import jexx.util.StringUtil;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Null;
import java.time.LocalDateTime;

@Data
@ApiModel(value="出库记录查询", description="出库记录查询")
public class ajManageBackPageSearch {

    @ApiModelProperty(value = "案卷名称")
    private String name;

    @ApiModelProperty(value = "案卷编号")
    private String code;

    @ApiModelProperty(value = "开始时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startLogTime;

    @ApiModelProperty(value = "结束时间")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime endLogTime;

    public static LambdaQueryWrapper<JzManage> createWrap(ajManageBackPageSearch search){
        LambdaQueryWrapper<JzManage> wrapper = new LambdaQueryWrapper<>();
        if(search != null){
            if(StringUtil.hasText(search.getName())){
                wrapper.like(JzManage::getName, search.getName());
            }
            if(StringUtil.hasText(search.getCode())){
                wrapper.like(JzManage::getCode, search.getCode());
            }
            if(search.getStartLogTime() != null && search.getEndLogTime() != null){
                wrapper.between(JzManage::getRegistDate, search.getStartLogTime(), search.getEndLogTime());
            }
            else if(search.getStartLogTime() != null ){
                wrapper.ge(JzManage::getRegistDate, search.getStartLogTime());
            }
            else if(search.getEndLogTime() != null){
                wrapper.le(JzManage::getRegistDate, search.getEndLogTime());
            }
//            出库状态记录筛选
            wrapper.ne(JzManage::getStatus,"临时出库");
            wrapper.isNotNull(JzManage::getTempBackMan);
        }
        wrapper.orderByDesc(JzManage::getCreateTime);
        return wrapper;
    }

}
